// Copyright (c) 2023, json_wang and contributors
// For license information, please see license.txt

frappe.ui.form.on('CreatePurchaseReceipt', {
	refresh: function (frm) {
		// Custom buttons
		frm.add_custom_button('CreatePurchaseReceipt', () => {
			console.log('button clicked')
			create_purchase_receipt(frm)
		})
	}
});

function create_purchase_receipt(frm){
	frappe.call({
		method: "frappe_study.frappestudy.doctype.createpurchasereceipt.createpurchasereceipt.create_order",
		args:{
			source_doc: frm.doc
		},
		freeze: true,
		freeze_message: __("Creating Purchase Receipt ..."),
	}).then((r)=>{
		var doclist = frappe.model.sync(r.message);
		frappe.set_route("Form", doclist[0].doctype, doclist[0].name);
	});
}
